//
//  NameViewController.m
//  LocomotiveGuards
//
//  Created by zwj on 15-11-19.
//  Copyright (c) 2015年 REDOOR. All rights reserved.
//

#import "NameViewController.h"
#import "ProvinceViewController.h"
@interface NameViewController () <UITextFieldDelegate>
{
    UITextField *_fieldName;
    UIButton *_btnLast;
    UIButton *_btnNext;
}
@end

@implementation NameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addTitle:@"注册-身份验证"];
    [self configView];
}

- (void)configView
{
    //姓名label
    UILabel *nameLabel = [self createLabelFrame:CGRectMake(30*W, SCREEN_HEIGHT/2-85*H, SCREEN_WIDTH-60*W, 30*H) title:@"姓名" font:[UIFont systemFontOfSize:26]];
    [self.view addSubview:nameLabel];
    
    //姓名输入框
    _fieldName = [self createTextFieldFrame:CGRectMake(30*W, CGRectGetMaxY(nameLabel.frame)+20*H, SCREEN_WIDTH-60*W, 35*H) title:nil placeholder:@"请填写真实姓名"];
    _fieldName.returnKeyType = UIReturnKeyDone;
    _fieldName.delegate = self;
    [self.view addSubview:_fieldName];
    
    //上一步按钮
    _btnLast = [self addLastBtnTarget:self action:@selector(btnLastClicked:)];
    [self enableButton:_btnLast];
    
    //下一步按钮
    _btnNext = [self addNextBtnTarget:self action:@selector(btnNextClicked:)];
    [self disableButton:_btnNext];

}

#pragma mark - 点击事件
//上一步，返回【手机号码验证】页面
- (void)btnLastClicked:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//下一步，进入新页面
- (void)btnNextClicked:(id)sender
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:_fieldName.text forKey:@"personName"];
    ProvinceViewController *proCtrl = [ProvinceViewController new];
    [self.navigationController pushViewController:proCtrl animated:YES];
}

//收起键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [_fieldName resignFirstResponder];
}

#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSString *tempStr = [_fieldName.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    if ([tempStr isEqualToString:@""]) {
        [self disableButton:_btnNext];
    }
    else {
        [self enableButton:_btnNext];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [_fieldName resignFirstResponder];
    return YES;
}

#pragma mark -
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
